#include "sort.h"

void PrintfArray(int* a, int size)
{
	assert(a);

	for (int i = 0; i < size; i++)
	{
		printf("%d ", a[i]);
	}

	printf("\n");
}


void InsertSort(int* a, int size)
{
	assert(a);

	for (int i = 0; i < size - 1; i++)
	{
		int tmp = a[i + 1];
		int end = i;

		while (end >= 0)
		{
			if (tmp < a[end])
			{
				a[end + 1] = a[end];
				end--;
			}
			else
			{
				break;
			}
		}

		a[end + 1] = tmp;
	}

}




void ShellSort(int* a, int size)
{
	assert(a);
	int gap = size;

	while (gap > 1)
	{
		gap /= 2;
		for (int i = 0; i < size - gap; i += gap)
		{
			int end = i;
			int tmp = a[i + gap];

			while (end >= 0)
			{
				if (tmp < a[end])
				{
					a[end + gap] = a[end];
					end -= gap;
				}
				else
				{
					break;
				}
			}

			a[end + gap] = tmp;

		}

	}

}